<?php

use Phinx\Db\Adapter\MysqlAdapter;
use think\migration\Migrator;
use think\migration\db\Column;

class CreateTableVideoUrl extends Migrator
{
    public function up()
    {
        if (!$this->hasTable('short_url')) {
            $table = $this->table('short_url', ['engine' => 'MyISAM'])
                ->setId('id')
                ->setPrimaryKey('id')
                ->setComment('短链存放');
            $table->addColumn('url', 'string', ['limit' => 500, 'null' => false, 'comment' => '需要请求的链接'])
                ->addColumn('short_url', 'string', ['limit' => 200, 'null' => false, 'default' => '', 'comment' => '生成的地址'])
                ->addColumn('title', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => '视频标题'])
                ->addColumn('add_time', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '生成时间'])
                ->addColumn('robot_wxid', 'string', ['limit' => 100, 'null' => false, 'default' => '', 'comment' => '机器人ID'])
                ->addIndex(['robot_wxid','short_url'])
                ->create();
        }
    }

    public function down()
    {
        if ($this->hasTable('short_url')) {
            $this->dropTable('short_url');
        }
    }
}
